package org.esgi.dao;

import java.io.File;
import java.util.List;

import org.esgi.model.interfaces.IUser;
import org.esgi.repository.impl.XMLUserRepository;
import org.esgi.repository.interfaces.IUserRepository;

public class UserDao implements IUserRepository
{
	private static UserDao sharedUserDao_ = null;

	private IUserRepository userRepository_;
	
	public static UserDao getSharedUserDao()
	{
		if(UserDao.sharedUserDao_ == null)
			UserDao.sharedUserDao_ = new UserDao();
		return UserDao.sharedUserDao_;
	}

	private UserDao() {}

	public void setFile(File file)
	{
		this.userRepository_ = new XMLUserRepository(file);
	}

	@Override
	public Boolean addUser(IUser u) 
	{
		return this.userRepository_.addUser(u);
	}

	@Override
	public Boolean deleteUser(IUser u) 
	{
		return this.userRepository_.deleteUser(u);
	}

	@Override
	public IUser getUser(String log, String pwd)
	{
		return this.userRepository_.getUser(log, pwd);
	}

	@Override
	public IUser getUser(String log, String pwd, Boolean secured) 
	{
		return this.userRepository_.getUser(log, pwd, secured);
	}

	@Override
	public List<IUser> getAllUsers() 
	{
		return this.userRepository_.getAllUsers();
	}
	
	@Override
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("UserDao (\n");
		sb.append(this.getAllUsers());
		sb.append(")");
		return sb.toString();
	}
}
